/*
 * @Author: 杰编程 2306248989@qq.com
 * @Date: 2023-07-25 12:08:07
 * @LastEditors: 杰编程 2306248989@qq.com
 * @LastEditTime: 2023-07-25 12:25:01
 * @FilePath: /lesson20/lockGuard.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once

#include<pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex):_pmutex(mutex)
    {}
    void lock()
    {
        pthread_mutex_lock(_pmutex);
    }
    void umlock()
    {
        pthread_mutex_unlock(_pmutex);
    }
private:
    pthread_mutex_t* _pmutex;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex):_mutex(mutex)
    {
        _mutex.lock();
    }
    ~LockGuard()
    {
        _mutex.umlock();
    }

private:
    Mutex _mutex;
};
